package com.tarena.lbs.attach.dao.repository.impl;


import com.tarena.lbs.attach.dao.mapper.AttachMapper;
import com.tarena.lbs.attach.dao.repository.AttachRepository;
import com.tarena.lbs.attach.pojo.dto.AttachDTO;
import com.tarena.lbs.attach.pojo.param.AttachParam;
import com.tarena.lbs.attach.pojo.param.PicUpdateParam;
import com.tarena.lbs.attach.pojo.po.AttachPO;
import com.tarena.lbs.attach.pojo.query.AttachQuery;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;


@Slf4j
@Repository
public class AttachRepositoryImpl implements AttachRepository {
    @Autowired
    private AttachMapper attachMapper;
    @Override
    public void insertAttach(AttachPO attach) {
        attachMapper.insertAttach(attach);
    }

    @Override
    public List<AttachPO> selectAttachByQuery(AttachQuery attachQuery) {
        return attachMapper.selectAttachByQuery(attachQuery);
    }

    @Override
    public int batchUpdateAttachByIdOrFileUUID(List<PicUpdateParam> picParams) {
        return attachMapper.batchUpdateAttachByIdOrFileUUID(picParams);
    }

    @Override
    public AttachDTO insertAttachInfo(AttachParam attachParam) {
        log.info("仓储层插入附件信息：{}", attachParam);
        AttachPO attachPO = new AttachPO();
        attachPO.setGmtCreate(new Date().getTime());

        BeanUtils.copyProperties(attachParam, attachPO);


        attachMapper.insert(attachPO);

        AttachDTO attachDTO = new AttachDTO();
        BeanUtils.copyProperties(attachParam, attachDTO);
        return attachDTO;
    }
}
